<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>确认密码</title>
<script>
  function confirm1(a, b) {
    if (a === "" || b === "")
      alert("密码字段值为空");
    else if (a === b)
      alert("true");
    else
      alert("false");
  }
  function confirm2() {
    var c = document.form1.password1.value;
    var d = document.form1.password2.value;
    if (c === "" || d === "")
      alert("密码字段值为空");
    else if (c === d)
      alert("true");
    else
      alert("false");
  }
</script>
</head>
<body>
  <form name="form1">
    <label>
      输入密码
      <input type="password" name="password1">
    </label>
    <br>
    <label>
      重复密码
      <input type="password" name="password2">
    </label>
    <br>
    <input type="button" value="confirm1" onclick="confirm1(password1.value, password2.value)">
    <input type="button" value="confirm2" onclick="confirm2()">
  </form>
</body>
</html>